<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/10/26 0026
  Time: 下午 1:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="/static/plugins/layui/css/layui.css">
    <link rel="stylesheet" href="/static/css/common.css">

</head>
<body>
    <div class="box-form">
        <form class="layui-form" id="rsePwdForm" action="/logout">
            <div class="layui-form-item">
                <label class="layui-form-label">用户密码：</label>
                <div class="layui-input-block">
                    <input type="password" name="pwd"  lay-verify="required|password" placeholder="请输入原有密码" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">新密码：</label>
                <div class="layui-input-block">
                    <input type="password" name="newPwd" id="newPwd" lay-verify="required|password" placeholder="请输入新密码" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">重复密码：</label>
                <div class="layui-input-block">
                    <input type="password" name="newPwd2"  lay-verify="required" placeholder="请输入重复密码" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formSubmit" >提交</button>
                    <a href="/" target="_top"><button type="button" class="layui-btn layui-btn-primary">取消</button></a>
                </div>
            </div>

        </form>
    </div>

    <script src="/static/js/plugins/jquery.js"></script>
    <script src="/static/plugins/layui/layui.js"></script>

    <script>
        layui.use(['element','layer','form'],function () {
            var form = layui.form
            var layer = layui.layer

            form.on('submit(formSubmit)',function (data){
                var serialize = $("#rsePwdForm").serialize();
                $.ajax({
                    url:"/user/resetPass",
                    type:"post",
                    dataType:"json",
                    data:serialize,
                    success:function (msg) {
                        if( msg.code == 1){
                            layer.msg("密码修改成功,请重新登录",{icon:1})
                            setTimeout(function () {
                                parent.location.href = "/logout"
                            },1500)
                        }else{
                            layer.msg(msg.data,{icon:2,time:1000})
                        }
                    },
                    error:function () {
                        layer.msg("密码修改失败")
                    }
                })
                return false

            })


            form.verify({
                password: [
                    /^[\S]{6,12}$/
                    ,'密码必须6到12位，且不能出现空格'
                ]
            })
        })

        function mySubmit() {
            $("#rsePwdForm").submit();  //校验通过提交表单
        }
    </script>
</body>
</html>
